﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;


[Serializable]
public class PersonInfoData
{

    public const string IDField = "@ID";

    public const string PRIMARYKEY_Field = @"ID";

    public const string EMAILField = "@email";

    public const string TITLEField = "@Title";

    public const string FIRSTNAMEField = "@FirstName";

    public const string LASTNAMEField = "@LastName";

    public const string ORGANIZATIONField = "@Organization";

    public const string DEPARTMENTField = "@Department";

    public const string COUNTRYField = "@Country";

    public const string ADDRESSField = "@Address";

    private Int32 _ID;

    private String _email;

    private String _Title;

    private String _FirstName;

    private String _LastName;

    private String _Organization;

    private String _Department;

    private String _Country;

    private String _Address;

    public Int32 ID
    {
        get { return _ID; }
        set { _ID = value; }
    }
    public String email
    {
        get { return _email; }
        set { _email = value; }
    }
    public String Title
    {
        get { return _Title; }
        set { _Title = value; }
    }
    public String FirstName
    {
        get { return _FirstName; }
        set { _FirstName = value; }
    }
    public String LastName
    {
        get { return _LastName; }
        set { _LastName = value; }
    }
    public String Organization
    {
        get { return _Organization; }
        set { _Organization = value; }
    }
    public String Department
    {
        get { return _Department; }
        set { _Department = value; }
    }
    public String Country
    {
        get { return _Country; }
        set { _Country = value; }
    }
    public String Address
    {
        get { return _Address; }
        set { _Address = value; }
    }
    public PersonInfoData()
    {
        _ID = 0;
        _email = "";
        _Title = "";
        _FirstName = "";
        _LastName = "";
        _Organization = "";
        _Department = "";
        _Country = "";
        _Address = "";
    }
}

public class PersonInfoDataFactory
{
    public static PersonInfoData Construct(IDataReader reader)
    {
        PersonInfoData data = new PersonInfoData();

        try { data.ID = Convert.ToInt32(reader["ID"]); }
        catch { }

        try { data.email = Convert.ToString(reader["email"]); }
        catch { }

        try { data.Title = Convert.ToString(reader["Title"]); }
        catch { }

        try { data.FirstName = Convert.ToString(reader["FirstName"]); }
        catch { }

        try { data.LastName = Convert.ToString(reader["LastName"]); }
        catch { }

        try { data.Organization = Convert.ToString(reader["Organization"]); }
        catch { }

        try { data.Department = Convert.ToString(reader["Department"]); }
        catch { }

        try { data.Country = Convert.ToString(reader["Country"]); }
        catch { }

        try { data.Address = Convert.ToString(reader["Address"]); }
        catch { }

        return data;
    }
    public static Int32 GetPrimaryKey(DataTable dt)
    {
        return GetPrimaryKey(dt, 0);
    }
    public static Int32 GetPrimaryKey(DataTable dt, int rowIndex)
    {
        Int32 PrimaryKey = 0;

        if (dt.Rows.Count < rowIndex + 1)

            return 0;

        DataRow dr = dt.Rows[rowIndex];

        if (dr == null)

            return 0;

        try { PrimaryKey = Convert.ToInt32(dr[PersonInfoData.PRIMARYKEY_Field]); }
        catch { }

        return PrimaryKey;
    }
    public static PersonInfoData Construct(DataTable dt)
    {
        return Construct(dt, 0);
    }
    public static PersonInfoData Construct(DataTable dt, int rowIndex)
    {
        PersonInfoData data = new PersonInfoData();

        if (dt.Rows.Count < rowIndex + 1)

            return null;

        DataRow dr = dt.Rows[rowIndex];

        if (dr == null)

            return null;

        try { data.ID = Convert.ToInt32(dr["ID"]); }
        catch { }

        try { data.email = Convert.ToString(dr["email"]); }
        catch { }

        try { data.Title = Convert.ToString(dr["Title"]); }
        catch { }

        try { data.FirstName = Convert.ToString(dr["FirstName"]); }
        catch { }

        try { data.LastName = Convert.ToString(dr["LastName"]); }
        catch { }

        try { data.Organization = Convert.ToString(dr["Organization"]); }
        catch { }

        try { data.Department = Convert.ToString(dr["Department"]); }
        catch { }

        try { data.Country = Convert.ToString(dr["Country"]); }
        catch { }

        try { data.Address = Convert.ToString(dr["Address"]); }
        catch { }

        return data;
    }
    public static PersonInfoData Construct(DataRow dr)
    {
        PersonInfoData data = new PersonInfoData();

        try { data.ID = Convert.ToInt32(dr["ID"]); }
        catch { }

        try { data.email = Convert.ToString(dr["email"]); }
        catch { }

        try { data.Title = Convert.ToString(dr["Title"]); }
        catch { }

        try { data.FirstName = Convert.ToString(dr["FirstName"]); }
        catch { }

        try { data.LastName = Convert.ToString(dr["LastName"]); }
        catch { }

        try { data.Organization = Convert.ToString(dr["Organization"]); }
        catch { }

        try { data.Department = Convert.ToString(dr["Department"]); }
        catch { }

        try { data.Country = Convert.ToString(dr["Country"]); }
        catch { }

        try { data.Address = Convert.ToString(dr["Address"]); }
        catch { }

        return data;
    }
    public static Int32 GetPrimaryKey(DataRow dr)
    {
        Int32 PrimaryKey = 0;

        try { PrimaryKey = Convert.ToInt32(dr[PersonInfoData.PRIMARYKEY_Field]); }
        catch { }
        return PrimaryKey;
    }

}
public class PersonInfoDataDBOption
{
    public static int Insert(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("insert into PersonInfo (");
        sql.Append("email, ");
        sql.Append("Title, ");
        sql.Append("FirstName, ");
        sql.Append("LastName, ");
        sql.Append("Organization, ");
        sql.Append("Department, ");
        sql.Append("Country, ");
        sql.Append("Address");
        sql.Append(") values (");
        sql.Append("'");
        sql.Append(d.email.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Title.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.FirstName.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.LastName.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Organization.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Department.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Country.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Address.ToString());
        sql.Append("'");
        sql.Append(")");
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static int Update(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("update PersonInfo set ");
        sql.Append("email=");
        sql.Append("'");
        sql.Append(d.email.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Title=");
        sql.Append("'");
        sql.Append(d.Title.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("FirstName=");
        sql.Append("'");
        sql.Append(d.FirstName.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("LastName=");
        sql.Append("'");
        sql.Append(d.LastName.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Organization=");
        sql.Append("'");
        sql.Append(d.Organization.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Department=");
        sql.Append("'");
        sql.Append(d.Department.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Country=");
        sql.Append("'");
        sql.Append(d.Country.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Address=");
        sql.Append("'");
        sql.Append(d.Address.ToString());
        sql.Append("'");
        sql.Append(" where ID=");
        sql.Append(d.ID.ToString());
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static int Delete(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("delete from PersonInfo ");
        sql.Append(" where ID=");
        sql.Append(d.ID.ToString());
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static DataTable DataTableSelect(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from PersonInfo ");
        return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
    }
    public static DataSet DataSetSelect(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from PersonInfo ");
        return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
    }
    public static SqlDataReader ReaderSelect(PersonInfoData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from PersonInfo ");
        return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
    }
}